/*
 * 
 * Created on Jul 30, 2005
 */
package com.wgo.precise.client.ui.view.util;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

import com.wgo.precise.client.ui.model.NodeChild;
import com.wgo.precise.client.ui.model.facade.ITreeItem;


/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: ExtendedViewerSorter.java,v 1.2 2006-02-19 16:29:37 petterei Exp $
 */
public class ExtendedViewerSorter extends ViewerSorter {

    /**
     * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
     */
    @Override
    public int category(Object element) {
        if (element instanceof ITreeItem) {
            return ((ITreeItem)element).getSortingOrder();
        }
        return 0;
    }

	/**
	 * Need to do this because of * when dirty..
	 * 
	 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	@Override
	public int compare(Viewer viewer, Object e1, Object e2) {
		int i = 0;
		int i1 = category(e1);
		int i2 = category(e2);
		if (i1 < i2) {
			i = -1;
		} else if (i1 > i2) {
			i = 1;
		} else {
			if (e1 instanceof NodeChild && e2 instanceof NodeChild) {
				i = ((NodeChild)e1).compareTo((NodeChild) e2);
			} else {
				i = super.compare(viewer, e1, e2);
			}
		}
		return i;
	}



}
/**
 * Changelog:
 * 
 * $Log: ExtendedViewerSorter.java,v $
 * Revision 1.2  2006-02-19 16:29:37  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.2  2005-09-29 16:41:42  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/09/27 21:06:28  petterei
 * *** empty log message ***
 *
 * 
 */